﻿using MSAcademic.v2.Infrastructure.AccessRights;
using MSAcademic.v2.Infrastructure.Login;
using MSAcademic.v2.Infrastructure.Tag;
using MSAcademic.v2.Infrastructure.User;

using StructureMap;
using System;

namespace MSAcademic.v2.Web.Areas.Admin.Models.Tag
{
    public partial class EditTagModel
    {
        public int TagId { get; set; }

         public ITag Tag
        {
            get
            {
                if (_tag == null)
                {
                    _tag = new Lazy<ITag>(() =>  _tagQueries.Get(TagId));
                }
                return _tag.Value;
            }
        }
        private Lazy<ITag> _tag;
    }

    public partial class EditTagModel
    {
        public IUser SignedInUser
        {
            get
            {
                if (_signedInUser == null)
                {
                    _signedInUser = new Lazy<IUser>(() => _loginService.TryGetSignedInUser());
                }
                return _signedInUser.Value;
            }
        }
        private Lazy<IUser> _signedInUser;

        public bool CanAccess
        {
            get
            {
                if (_canAccess == null)
                {
                    _canAccess = new Lazy<bool>(() => this.SignedInUser != null && _accessRightsService.CanUserAccess(this.SignedInUser, AccessRight.TagControl));
                }
                return _canAccess.Value;
            }
        }
        private Lazy<bool> _canAccess;
    }

    public partial class EditTagModel
    {
        private readonly ILoginService _loginService;
        private readonly IAccessRightsService _accessRightsService;
        private ITagQueries _tagQueries;

        public EditTagModel(
            ILoginService loginService,
            IAccessRightsService accessRightsService)
        {
            _loginService = loginService;
            _accessRightsService = accessRightsService;
            _tagQueries = ObjectFactory.GetInstance<ITagQueries>();
        }
    }
  
}